import React, { Component } from 'react'

export default class App extends Component {
  state = {
    bBar: false,
  }
  inputRef = React.createRef()
  // 需求：点击回复按钮，显示 input 框【并聚焦】
  handleClick = () => {
    // !建议
    /* this.setState({ bBar: !this.state.bBar }, () => {
      // 获取 DOM 并聚焦
      this.inputRef.current.focus()
    }) */
    this.setState({ bBar: !this.state.bBar })
  }
  render() {
    return (
      <div>
        App
        {this.state.bBar && <input type='text' ref={this.inputRef} />}
        <button onClick={this.handleClick}>回复</button>
      </div>
    )
  }
  componentDidUpdate() {
    this.inputRef.current.focus()
  }
}
